package com.ruoyi.system.vis.service.impl;

import com.ruoyi.drug.domain.DrugPhysic;
import com.ruoyi.drug.mapper.DrugPhysicMapper;
import com.ruoyi.system.domain.SysCheck;
import com.ruoyi.system.vis.mapper.VisPreDrugMapper;
import com.ruoyi.system.vis.service.VisPreDrugService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class VisPreDrugServiceImpl implements VisPreDrugService {
    @Autowired
    private VisPreDrugMapper visPreDrugMapper;
   @Autowired
   private DrugPhysicMapper drugPhysicMapper;

    @Override
    public List<DrugPhysic> selectCheckByPatientId(Long patientId) {
        ArrayList<DrugPhysic> list = new ArrayList<>();
        long[] ids = visPreDrugMapper.selectByPatientId(patientId);
        for (long id : ids) {
            DrugPhysic drugPhysic = drugPhysicMapper.selectPhysicById(id);
            list.add(drugPhysic);
        }
        return list;
    }

    @Override
    public int add(Long patientId, Long[] drugIds) {
        int count=0;
        for (Long drugId : drugIds) {
            visPreDrugMapper.addDrug(patientId, drugId);
            count++;
        }
        return count;
    }
}
